<?php
    include('includes/connect.php');
    include('includes/function/general.php');
	
    if(isset($_REQUEST['mode'])&& $_REQUEST['mode']=='lapundelievered')
	{
	$sql = mysql_query("SELECT  ral.date,lpt.region,lpt.division,lpt.laptopmodel,lpt.serial_no,lpt.depot_location,lpt.dispatch_location,usr.user_no,usr.user_firstname,usr.user_lastname,usr.user_designation,lpt.user_name,lpt.date,lpt.laptop_id FROM users as usr INNER JOIN  laptop as lpt ON  usr.user_id = lpt.user_id  INNER JOIN  received_laptop  as ral ON ral.laptop_id = lpt.laptop_id and lpt.dispatch='0'");
	
    $data='';
	  $column[]="Employee Number";
	  $column[]="Employee Name";
	  $column[]="Employee Designation";
	  $column[]="Division";
	  $column[]="Region"; 
	  $column[]="Laptop Model";	
	  $column[]="Laptop Serial Number"; 
	  $column[]="Depot Location";
	  $column[]="Dispatch Location";
	  $column[]="Date";
	  $column[]="Requested By";
	  $column[]="Request Date";
	  $column[]="Box No";
	  
	  
   $excelName='laptopundelireport';
   	  if(mysql_num_rows($sql)>0)
	    {
		  $i=0;
		  while($row=mysql_fetch_array($sql))
		    {
			  $data[$i][]=$row['user_no'];
			  $data[$i][]=$row['user_firstname'].' '.$row['user_lastname'];
			  $data[$i][]=$row['user_designation'];
			  $data[$i][]=$row['division'];
			  $data[$i][]=$row['region'];
			  $data[$i][]=$row['laptopmodel'];
			  $data[$i][]=$row['serial_no'];
			  $data[$i][]=$row['depot_location'];
			  $data[$i][]=$row['dispatch_location'];
			  $data[$i][]=$row[0];
			  $data[$i][]=$row['user_name'];
			  $data[$i][]=$row[12];
			  $sql2=mysql_query("select box_no from laptop_details where laptop_id='".$row['laptop_id']."'");
			  $result25=mysql_fetch_row($sql2);
			  $data[$i][]=$result25[0];
			  $i++;
			} 
		
		}
	}
	
	
if(isset($_REQUEST['mode'])&& $_REQUEST['mode']=='pendingLaptop')
 {
    $sql='';   
	$id=$_GET['id'];
	if($id==1)
    {
//added by bhavika previous was lpt.dispatch !=1
     $sql = mysql_query("SELECT DISTINCT usr.user_no, usr.user_firstname, usr.user_lastname, usr.user_designation, lpt.depot_location,lpt.division, lpt.laptopmodel,usr.depot,lpt.dispatch_location,lpt.region, lpt.dispatch_date, lpt.laptop_id,lpt.serial_no,apl.date FROM users AS usr INNER JOIN laptop AS lpt ON usr.user_id = lpt.user_id INNER JOIN approved_laptops as apl ON apl.laptop_id=lpt.laptop_id WHERE lpt.status = 'approve' AND lpt.assigned =1 AND lpt.recived=0 AND lpt.returned=0 AND lpt.dispatch=0 "); 
    }
   elseif($id==2)
    {
      $sql = mysql_query("SELECT * FROM users AS usr INNER JOIN laptop AS lpt ON usr.user_id = lpt.user_id INNER JOIN disapproved_laptops as dpl ON lpt.laptop_id=dpl.laptop_id"); 
    }
	  $data='';
	  $column[]="Employee Number";
	  $column[]="Employee Name";
	  $column[]="Employee Designation";
	  $column[]="Region";
	  $column[]="Division";
	  $column[]="From Depot";
	  $column[]="To Depot";	
	    if($id==1)
		  {
		    $column[]="Approve Date";
		  }
		else
		  {
		    $column[]="Request Date";
		  }  
	  $column[]="Laptop Model";
	  //$column[]="Depot Location";
	  //$column[]="Dispatch Location";
	  
	  $excelName='pendinglaptopreport';
	  if(mysql_num_rows($sql)>0)
		  {
		     $i=0;
			 while($row=mysql_fetch_array($sql))
		      {
			    $data[$i][]=$row['user_no'];
			    $data[$i][]=$row['user_firstname'].' '.$row['user_lastname'];
			    $data[$i][]=$row['user_designation'];
				$data[$i][]=$row['region'];
				$data[$i][]=$row['division'];
			    $data[$i][]=$row['depot_location'];
			    $data[$i][]=$row['dispatch_location'];
				 if($id==1)
				   {
				      $data[$i][]=$row['date'];
				   }
				  else
				    {
					  $data[$i][]=$row['date'];
					} 
				//$data[$i][]=$row['date'];
			    $data[$i][]=$row['laptopmodel'];
			    
			    //$data[$i][]=$row['depot_location'];
			    //$data[$i][]=$row['dispatch_location'];
			    $i++;
			} 
	
	  } 
 }
 
 
 if(isset($_REQUEST['mode'])&& $_REQUEST['mode']=='pendingAccessories')
 {
    $sql='';
	$data='';
	$id=$_GET['id'];
	if($id==1)
     {
      $sql=mysql_query("select usr.user_no,usr.user_firstname,acc.company_name,usr.user_lastname,usr.user_designation,acc.division,acc.region,acc.depot_location,acc.dispatch_location,acc.card_no,appacc.date from users as usr INNER JOIN accessories AS acc ON acc.user_id=usr.user_id INNER JOIN approved_accessories AS appacc ON appacc.accessories_id=acc.accessories_id where acc.status='approve' and acc.assigned=1 AND acc.received=0 AND acc.returned=0 AND acc.dispatch=0 ");
    }
   else
     {
	  $sql = mysql_query("SELECT * FROM users AS usr INNER JOIN accessories AS acc ON usr.user_id = acc.user_id INNER JOIN disapproved_accessories  as dacc ON acc.accessories_id=dacc.accessories_id");
	 }

$excelName='laptopDelieverReport';

						 $column[]="Employee Number";
						 $column[]="Employee Name";
						 $column[]="Designation";
						 $column[]="Division";
						 $column[]="Region";					
						 $column[]="From Depot";
						 $column[]="To Depot";
						 $column[]="Delievery Date";
						 //</tr>';
						if($id==1)
						  {
						    $column[]="Approve Date";
						  }
						else
						  {
						     $column[]="Request Date";
						  } 
if(mysql_num_rows($sql)>0)
 { 
   $i=0;					  
   while($result = mysql_fetch_array($sql))
   {
             $data[$i][]=$result['user_no'];
			 $data[$i][]=$result['user_firstname'].' '.$result['user_lastname'];
			 $data[$i][]=$result['user_designation'];
			 $data[$i][]=$result['region'];
			 $data[$i][]=$result['division'];
			 $data[$i][]=$result['depot_location'];				
			 $data[$i][]=$result['dispatch_location'];
			 $data[$i][]=$result['company_name'];
			 $data[$i][]=$result['card_no'];
						  if($id==1)
						    {
							   $data[$i][]=$result['date'];
							}
						   else
						     {
							   $data[$i][]=$result['date'];
							 }	    
						//<td align="center">'.$result['date'].'</td>
						
						//</tr>';
			   		$i++;
						}
   }
 }
 
//added today 12.35
 
 if(isset($_REQUEST['mode'])&& $_REQUEST['mode']=='lapdispatched')
 {
   $value1=$_GET['startDate'];
   $value2=$_GET['endDate'];
   $excelName='laptopDispatchedReport';
   $data='';
   $sql = mysql_query("SELECT usr.user_no,usr.user_firstname,usr.user_lastname,usr.user_designation,usr.depot,lpt.division,lpt.region,lpt.laptopmodel,lpt.serial_no,lpt.depot_location,lpt.dispatch_location,asl.date,lpt.user_name,lpt.date,lpt.laptop_id   FROM users as usr INNER JOIN  laptop as lpt ON  usr.user_id = lpt.user_id INNER JOIN  assigned_laptops as asl ON asl.laptop_id = lpt.laptop_id where asl.Date>='".$value1."' AND asl.Date<='".$value2 ."'");
	
						 $column[]="Employee Number";
						 $column[]="Employee Name";
						 $column[]="Designation";
						 $column[]="Division";
						 $column[]="Region";
						 $column[]="Report to Depot";
						 $column[]="Laptop Model";
						 $column[]="Laptop Serial Number";					
						 $column[]="From Depot";
						 $column[]="To Depot";
						 $column[]="Delievery Date";
						 $column[]="Requested By";
						 $column[]="Date";
						 $column[]="Box Number"; 
						 
if(mysql_num_rows($sql)>0)
 { 
   $i=0;					  
   while($result = mysql_fetch_array($sql))
   {
             $data[$i][]=$result['user_no'];
			 $data[$i][]=$result['user_firstname'].' '.$result['user_lastname'];
			 $data[$i][]=$result['user_designation'];
			 $data[$i][]=$result['division'];
			 $data[$i][]=$result['region'];
			 $data[$i][]=$result['depot'];
			 $data[$i][]=$result['laptopmodel'];
			 $data[$i][]=$result['serial_no'];
			 $data[$i][]=$result['depot_location'];				
			 $data[$i][]=$result['dispatch_location'];
			 $data[$i][]=$result['11'];
			 $data[$i][]=$result['user_name'];
			 $data[$i][]=$result['13'];
			 $sql2=mysql_query("select box_no from laptop_details where laptop_id='".$result['laptop_id']."'");
			 $result25=mysql_fetch_row($sql2);
			 $data[$i][]=$result25[0];
			 $i++;
	}
   }
 }
 
 if(isset($_REQUEST['mode'])&& $_REQUEST['mode']=='accdispatched')
 {
   $value1=$_GET['startDate'];
   $value2=$_GET['endDate'];
   $excelName='accDispatchReport';
   $data='';
   $sql = mysql_query("SELECT  usr.user_no,usr.user_firstname,usr.user_lastname,usr.user_designation,usr.depot,acc.division,acc.region,acc.accessories_name,acc.card_no,acc.depot_location,acc.dispatch_location,asa.*  FROM users as usr INNER JOIN  accessories  as acc ON  usr.user_id = acc.user_id INNER JOIN  assigned_accessories  as asa ON asa.accessories_id = acc.accessories_id where asa.Date>='".$value1."' AND asa.Date<='".$value2."'");
	
$excelName='laptopDelieverReport';

						 $column[]="Employee Number";
						 $column[]="Employee Name";
						 $column[]="Designation";
						 $column[]="Division";
						 $column[]="Region";
						 $column[]="Accessories Name";
						 $column[]="Card Number";
						 $column[]="From Depot";
						 $column[]="To Depot";
						 $column[]="Dispatch Date";
						 
if(mysql_num_rows($sql)>0)
 { 
   $i=0;					  
   while($result = mysql_fetch_array($sql))
   {
             $data[$i][]=$result['user_no'];
			 $data[$i][]=$result['user_firstname'].' '.$result['user_lastname'];
			 $data[$i][]=$result['user_designation'];
			 $data[$i][]=$result['division'];
			 $data[$i][]=$result['region'];
			 $data[$i][]=$result['accessories_name'];
			 $data[$i][]=$result['card_no'];
			 $data[$i][]=$result['depot_location'];				
			 $data[$i][]=$result['dispatch_location'];
			 $data[$i][]=$result['date'];
			 $i++;
	}
   }
 }
 
 if(isset($_REQUEST['mode'])&& $_REQUEST['mode']=='lapdelievered')
 {
 
   $value1=$_GET['startDate'];
   $value2=$_GET['endDate'];
   $excelName='lapDelievereReport';
   $data='';
   $sql = mysql_query("SELECT  usr.user_no,usr.user_firstname,usr.user_lastname,usr.user_designation,usr.depot,lpt.region,lpt.division,lpt.laptopmodel,lpt.serial_no,lpt.depot_location,lpt.dispatch_location,dsl.date,lpt.user_name,lpt.date,lpt.laptop_id FROM users as usr INNER JOIN  laptop as lpt ON  usr.user_id = lpt.user_id INNER JOIN  dispatched_laptop as dsl ON    dsl.laptop_id = lpt.laptop_id where dsl.date >='".$value1."'AND dsl.date <='".$value2."'");
	
$excelName='laptopDelieverReport';

						 $column[]="Employee Number";
						 $column[]="Employee Name";
						 $column[]="Designation";
						 $column[]="Report to depot";
						 $column[]="Division";
						 $column[]="Region";
						 $column[]="Laptop Model";
						 $column[]="Laptop Serial Number";
						 $column[]="From Depot";
						 $column[]="To Depot";
						 $column[]="Dispatch Date";
						 $column[]="Request By";
						 $column[]="Date";
						 $column[]="Box Number"; 
						 
if(mysql_num_rows($sql)>0)
 { 
   $i=0;					  
   while($result = mysql_fetch_array($sql))
   {
             $data[$i][]=$result['user_no'];
			 $data[$i][]=$result['user_firstname'].' '.$result['user_lastname'];
			 $data[$i][]=$result['user_designation'];
			 $data[$i][]=$result['depot'];
			 $data[$i][]=$result['division'];
			 $data[$i][]=$result['region'];
			 $data[$i][]=$result['laptopmodel'];
			 $data[$i][]=$result['serial_no'];
			 $data[$i][]=$result['depot_location'];				
			 $data[$i][]=$result['dispatch_location'];
			 $data[$i][]=$result[11];
			 $data[$i][]=$result['user_name'];
			 $data[$i][]=$result[13];
			 $sql2=mysql_query("select box_no from laptop_details where laptop_id='".$result['laptop_id']."'");
			 $result25=mysql_fetch_row($sql2);
			 $data[$i][]=$result25[0];
			 $i++;
	}
   }
 }
 
 
 if(isset($_REQUEST['mode'])&& $_REQUEST['mode']=='accdelievered')
 {
   $value1=$_GET['startDate'];
   $value2=$_GET['endDate'];
   $excelName='accDelievereReport';
   $data='';
   $sql = mysql_query("SELECT  usr.user_no,usr.user_firstname,usr.user_lastname,usr.user_designation,usr.depot,acc.region,acc.division,acc.accessories_name,acc.card_no,acc.depot_location,acc.dispatch_location,dsl.*  FROM users as usr INNER JOIN  accessories  as acc ON  usr.user_id = acc.user_id INNER JOIN  dispatched_accessories  as dsl ON dsl.accessories_id = acc.accessories_id where dsl.date >='".$value1."'AND dsl.date <='".$value2."'");
	
$excelName='laptopDelieverReport';

						 $column[]="Employee Number";
						 $column[]="Employee Name";
						 $column[]="Employee Designation";
						 $column[]="Report to Depot";
						 $column[]="Region";
						 $column[]="Division";
						 $column[]="Accessories Name";
						 $column[]="Card Number";
						 $column[]="From Depot";
						 $column[]="To Depot";
						 $column[]="Delivery Date";
						 
if(mysql_num_rows($sql)>0)
 { 
   $i=0;					  
   while($result = mysql_fetch_array($sql))
   {
             $data[$i][]=$result['user_no'];
			 $data[$i][]=$result['user_firstname'].' '.$result['user_lastname'];
			 $data[$i][]=$result['user_designation'];
			 $data[$i][]=$result['depot'];
			 $data[$i][]=$result['region'];
			 $data[$i][]=$result['division'];
			 $data[$i][]=$result['accessories_name'];
			 $data[$i][]=$result['card_no'];
			 $data[$i][]=$result['depot_location'];				
			 $data[$i][]=$result['dispatch_location'];
			 $data[$i][]=$result['date'];
			 $i++;
	}
   }
 }
 
 if(isset($_REQUEST['mode'])&& $_REQUEST['mode']=='empQueryReport')
 {
   $value1=$_GET['empid'];
   $excelName='empQueryReport';
   $data='';
   $sql=mysql_query("SELECT  usr.user_no,usr.user_firstname,usr.user_lastname,usr.user_telno,usr.user_address,usr.user_email_address,usr.user_designation,usr.depot,lpt.laptopmodel,lpt.division,lpt.region,lpt.serial_no,acc.accessories_name,acc.card_no,lpt.depot_location,lpt.dispatch_location,lptd.box_no,dlap.date from users as usr INNER JOIN laptop as lpt ON usr.user_id=lpt.user_id INNER JOIN dispatched_laptop as dlap ON dlap.laptop_id=lpt.laptop_id INNER JOIN accessories as acc ON usr.user_id=acc.user_id INNER JOIN laptop_details as lptd ON lptd.laptop_id=lpt.laptop_id where usr.user_no='".trim( $value1)."'");
	
$excelName='laptopDelieverReport';

						 $column[]="Employee Number";
						 $column[]="Employee Name";
						 $column[]="Employee Tel NO";
						 $column[]="Employee Address";
						 $column[]="Employee Email Address";
						 $column[]="Employee Designation";
						 $column[]="Report to Depot";
						 $column[]="Region";
						 $column[]="Division";
						 $column[]="Laptop Model";
						 $column[]="Serial Number"; 
						 $column[]="Box No";
						 $column[]="Laptop Holding Date";
						 $column[]="Accessories Name";
						 $column[]="Card Number";
						 $column[]="From Depot";
						 $column[]="To Depot";
						 $column[]="Box Number"; 
						 
						 
if(mysql_num_rows($sql)>0)
 { 
   $i=0;					  
   while($result = mysql_fetch_array($sql))
   {
             $data[$i][]=$result['user_no'];
			 $data[$i][]=$result['user_firstname'].' '.$result['user_lastname'];
			 $data[$i][]=$result['user_telno'];
			 $data[$i][]=$result['user_address'];
			 $data[$i][]=$result['user_email_address'];
			 $data[$i][]=$result['user_designation'];
			 $data[$i][]=$result['depot'];
			 $data[$i][]=$result['region'];
			 $data[$i][]=$result['division'];
			 $data[$i][]=$result['laptopmodel'];
			 $data[$i][]=$result['serial_no'];
			 $data[$i][]=$result['box_no'];
			 $data[$i][]=$result['date'];
			 $data[$i][]=$result['accessories_name'];
			 $data[$i][]=$result['card_no'];
			 $data[$i][]=$result['depot_location'];				
			 $data[$i][]=$result['dispatch_location'];
			 $sql2=mysql_query("select box_no from laptop_details where laptop_id='".$row['laptop_id']."'");
			 $result25=mysql_fetch_row($sql2);
			 $data[$i][]=$result25[0];
			 $i++;
	}
   }
 }
 
  if(isset($_REQUEST['mode'])&& $_REQUEST['mode']=='queryonlap')
 {
   $value1=$_GET['lapname'];
   //echo $value1;
   $excelName='empQueryReport';
   $data='';
   $sql=mysql_query("SELECT usr.user_no, usr.user_firstname, usr.user_lastname, usr.user_telno, usr.user_address, usr.user_email_address, usr.user_designation, usr.depot, lpt.division, lpt.region, lpt.laptopmodel, lpt.dispatch_location,lpt.laptop_id,lpt.depot_location,lpt.serial_no, acc.accessories_name, acc.company_name, acc.card_no, lptd.box_no, acc.date FROM users AS usr INNER JOIN laptop AS lpt INNER JOIN accessories AS acc INNER JOIN laptop_details AS lptd ON lpt.user_id = usr.user_id AND acc.user_id = usr.user_id AND lptd.laptop_id = lpt.laptop_id AND acc.dispatch =1 AND lpt.dispatch =1 AND acc.returned !=1 AND lpt.returned !=1 AND lpt.serial_no = '".$value1."'");
	
$excelName='laptopDelieverReport';

						 $column[]="Employee Number";
						 $column[]="Employee Name";
						 $column[]="Employee Tel NO";
						 $column[]="Employee Address";
						 $column[]="Employee Email Address";
						 $column[]="Employee Designation";
						 $column[]="Report to Depot";
						 $column[]="Region";
						 $column[]="Division";
						 $column[]="Laptop Model";
						 $column[]="Serial Number"; 
						 $column[]="Laptop Holding Date";
						 $column[]="Accessories Name";
						 $column[]="Card Number";
						 $column[]="From Depot";
						 $column[]="To Depot";
						 $column[]="Box Number"; 
						 
						 
if(mysql_num_rows($sql)>0)
 { 
   $i=0;					  
   while($result = mysql_fetch_array($sql))
   {
             $data[$i][]=$result['user_no'];
			 $data[$i][]=$result['user_firstname'].' '.$result['user_lastname'];
			 $data[$i][]=$result['user_telno'];
			 $data[$i][]=$result['user_address'];
			 $data[$i][]=$result['user_email_address'];
			 $data[$i][]=$result['user_designation'];
			 $data[$i][]=$result['depot'];
			 $data[$i][]=$result['region'];
			 $data[$i][]=$result['division'];
			 $data[$i][]=$result['laptopmodel'];
			 $data[$i][]=$result['serial_no'];
			 $data[$i][]=$result['date'];
			 $data[$i][]=$result['accessories_name'];
			 $data[$i][]=$result['card_no'];
			 $data[$i][]=$result['depot_location'];				
			 $data[$i][]=$result['dispatch_location'];
			 $sql2=mysql_query("select box_no from laptop_details where laptop_id='".$result['laptop_id']."'");
			 $result25=mysql_fetch_row($sql2);
			 $data[$i][]=$result25[0];
			 $i++;
	}
   }
 }
 
  if(isset($_REQUEST['mode'])&& $_REQUEST['mode']=='accreport')
 {
   $value1=$_GET['startDate'];
   $value2=$_GET['endDate'];
   $excelName='accReport';
   $data='';
   $sql = mysql_query("SELECT count( accessories_id ), accessories_name FROM assigned_accessories, accessories_data WHERE accessories_id = accessoriesdata_id AND date >= '".$value1."'AND date <='".$value2."'GROUP BY accessories_id");
	

						 $column[]="Accessories Name";
						 $column[]="Total Number Of Accessories";
						
						 
if(mysql_num_rows($sql)>0)
 { 
   $i=0;					  
   while($result = mysql_fetch_array($sql))
   {
             $data[$i][]=$result['accessories_name'];
			 $data[$i][]=$result['count( accessories_id )'];
			 $i++;
	}
   }
 }
 
 if(isset($_REQUEST['mode'])&& $_REQUEST['mode']=='accStockreport')
 {
   $value1=$_GET['startDate'];
   $value2=$_GET['endDate'];
   $excelName='accStockReport';
   $data='';
   $sql = mysql_query("SELECT ad.accessories_name, asd.quantity, asd.date,asd.depot_location FROM accessories_stock_details AS asd INNER JOIN accessories_data AS ad ON asd.accessories_id = ad.accessoriesdata_id WHERE date >= '".$value1."'AND date <='".$value2."'");
	

						 $column[]="Accessories Name";
						 $column[]="Quantity";
						 $column[]="Depot";
						 $column[]="Date";
						
						 
if(mysql_num_rows($sql)>0)
 { 
   $i=0;					  
   while($result = mysql_fetch_array($sql))
   {
             $data[$i][]=$result['accessories_name'];
			 $data[$i][]=$result['quantity'];
			 $data[$i][]=$result['depot_location'];
			 $data[$i][]=$result['date'];
			 $i++;
	}
   }
 }

if(isset($_REQUEST['mode'])&& $_REQUEST['mode']=='accStockDailyReport')
 {
   $value1=$_GET['tdate'];
   $excelName='accStockDailyReport';
   $data='';
   $sql = mysql_query("SELECT ad.accessories_name, asd.quantity, asd.depot_location FROM accessories_stock_details AS asd INNER JOIN accessories_data AS ad ON asd.accessories_id = ad.accessoriesdata_id WHERE asd.date = '".$value1."'");
	

						 $column[]="Accessories Name";
						 $column[]="Quantity";
						 $column[]="Depot";
						
						
						 
if(mysql_num_rows($sql)>0)
 { 
   $i=0;					  
   while($result = mysql_fetch_array($sql))
   {
             $data[$i][]=$result['accessories_name'];
			 $data[$i][]=$result['quantity'];
			 $data[$i][]=$result['depot_location'];
			
			 $i++;
	}
   }
 }
 
 
 if(isset($_REQUEST['mode'])&& $_REQUEST['mode']=='laptopindepot')
 {
   $excelName='laptopDepotReport';
   $data='';
   $id=$_GET['laptype'];
   if($id=="1")
     {
	  $sql=mysql_query("Select laptop_name ,laptop_model,box_no,serial_no,depot_location,laptop_type from laptop_details where status='1' and laptop_type='O' order by depot_location ASC");
	 }
	 elseif($id=="2")
	 {
	  $sql=mysql_query("Select laptop_name ,laptop_model,box_no,serial_no,depot_location,laptop_type from laptop_details where status='1' and laptop_type='S' order by depot_location ASC");
	 }
	 elseif($id=="3")
	 {
	  $sql=mysql_query("Select laptop_name ,laptop_model,box_no,lpt.serial_no,depot_location,laptop_type from laptop_details AS lpt INNER JOIN return_laptop AS rlpt ON rlpt.laptop_id=lpt.laptop_id where rlpt.status='TakenHome' order by depot_location ASC"); 
	 }
	 else
	 {
	    
	 }
	

						 $column[]="Laptop Name";
						 $column[]="Laptop Model";
						 $column[]="Laptop Serial Number";
						 $column[]="Box Number";
						 $column[]="Depot Location";
						 $column[]="Laptop Type";
if(mysql_num_rows($sql)>0)
 { 
   $i=0;					  
   while($result = mysql_fetch_array($sql))
   {
             $data[$i][]=$result[0];
			 $data[$i][]=$result[1];
			 $data[$i][]=$result[2];
			 $data[$i][]=$result[3];
			 $data[$i][]=$result[4];
			 if($result[5]=='S')
			   {
			    	 $data[$i][]="Substitute";
			   }
			   else
			   {
			       $data[$i][]="Original";
			   }		 
			 $i++;
	}
   }
 }
 
  if(isset($_REQUEST['mode'])&& $_REQUEST['mode']=='laptopstatus')
   {
      $excelName='laptopStatusReport';
      $data='';
	   $id=$_GET['status'];
	    if($id=="1")
		  {
		   $sql = mysql_query("SELECT usr.user_no, usr.user_firstname, usr.user_lastname, usr.user_designation, usr.user_doj, usr.depot, lpt.division, lpt.region, lpt.laptopmodel, lpt.depot_location, lpt.dispatch_location, lpt.serial_no, lpd.box_no, lpd.laptop_type, lpt.user_name, lpt.date
FROM users AS usr INNER JOIN laptop AS lpt INNER JOIN laptop_details AS lpd ON usr.user_id = lpt.user_id AND lpt.laptop_id = lpd.laptop_id and lpd.status='0' and lpd.laptop_type!='L' and lpd.laptop_type!='X' and lpd.laptop_type!='R' and lpd.laptop_type!='D'"); 
		  }	
	    else
		{
		  $sql = mysql_query("SELECT usr.user_no,usr.user_firstname,usr.user_lastname,usr.user_designation,usr.user_doj,usr.depot,lpt.division,lpt.region,lpt.laptopmodel,lpt.depot_location,lpt.dispatch_location,lpt.serial_no,lpd.box_no,lpd.laptop_type,lpt.user_name,lpt.date FROM  users as usr INNER JOIN  laptop as lpt INNER JOIN laptop_details as lpd ON usr.user_id=lpt.user_id AND lpt.laptop_id=lpd.laptop_id AND laptop_type='R'");
		}	
		
		                 $column[]="User No";
						 $column[]="User Name";
						 $column[]="User Designation";
						 $column[]="Laptop Model";
						 $column[]="Serial No";
						 $column[]="Box No";  
                         $column[]="Division";
						 $column[]="Region";
						 $column[]="Depot";
						 $column[]="Dispatch Location";
						 $column[]="Depot Location";
						 $column[]="Date of Joinning";
						 $column[]="Requested By";
						 $column[]="Requested Date";
						 $column[]="Laptop Type";
						
    if(mysql_num_rows($sql)>0)
     {
           $i=0;					  
           while($result = mysql_fetch_array($sql))
            {
			  $data[$i][]=$result['user_no'];
			  $data[$i][]=$result['user_firstname'].' '. $result['user_lastname'];
			  $data[$i][]=$result['user_designation'];
			  $data[$i][]=$result['laptopmodel'];
			  $data[$i][]=$result['serial_no'];
			  $data[$i][]=$result['box_no'];
			  $data[$i][]=$result['division'];
			  $data[$i][]=$result['region'];
			  $data[$i][]=$result['depot'];
			  $data[$i][]=$result['dispatch_location'];
			  $data[$i][]=$result['depot_location'];
			  $data[$i][]=$result['user_doj'];
			  $data[$i][]=$result['user_name'];
			  $data[$i][]=$result['date'];
			     if($result['laptop_type']=='S')
			      {
			    	  $data[$i][]="Substitute";
			      }
			     else
			      {
			         $data[$i][]="Original";
			      }	
				  $i++;	 
			}
		}
  }	
  
   if(isset($_REQUEST['mode'])&& $_REQUEST['mode']=='lapQueryReport')
   {
     $data='';
	 $id=$_GET['emp_no'];
	 $excelName="queryEmpReport";
	 $sql=mysql_query('SELECT usr.user_no, usr.user_firstname, usr.user_lastname, usr.user_telno, usr.user_address, usr.user_email_address, usr.user_designation, usr.depot, lpt.division, lpt.region, lpt.laptopmodel, lpt.serial_no, acc.accessories_name, acc.company_name, acc.card_no, lptd.box_no,acc.date FROM users AS usr INNER JOIN laptop AS lpt INNER JOIN accessories AS acc INNER JOIN laptop_details AS lptd ON lpt.user_id = usr.user_id AND acc.user_id = usr.user_id AND lptd.laptop_id = lpt.laptop_id AND acc.dispatch =1 AND usr.user_no = "'.$id.'"');
        
		                 $column[]="User No";
						 $column[]="User Name";
						 $column[]="Designation";
						 $column[]="Telephone Number";
						 $column[]="Address";
						 $column[]="Email-address";  
                         $column[]="Depot";
						 $column[]="Division";
						 $column[]="Region";
						 $column[]="Laptop Model Name";
						 $column[]="Serial Number";
						 $column[]="Box";
						 $column[]="Accessories Name";
						 $column[]="Company Name";
						 $column[]="Card Number";
						 $column[]="Date";
						 
			if(mysql_num_rows($sql)>0)
             {
              $i=0;					  
                while($result = mysql_fetch_array($sql))
                {
					   $data[$i][]=$result['user_no'];
					   $data[$i][]=$result['user_firstname'].' '. $result['user_lastname'];
					   $data[$i][]=$result['user_designation'];
					   $data[$i][]=$result['user_telno'];
					   $data[$i][]=$result['user_address'];
					   $data[$i][]=$result['user_email_address'];
					   $data[$i][]=$result['depot'];
					   $data[$i][]=$result['division'];
					   $data[$i][]=$result['region'];
					   $data[$i][]=$result['laptopmodel'];
					   $data[$i][]=$result['serial_no'];
					   $data[$i][]=$result['box_no'];
					   $data[$i][]=$result['accessories_name'];
					   $data[$i][]=$result['company_name'];
					   $data[$i][]=$result['card_no'];
					   $data[$i][]=$result['date'];	
					   $i++;	 
			 }
		}		 
						 
   }
  		  
 $excelFileName=date('d-m-Y').$excelName.'-'."Report.xls";
 displayArrayTableExportExcel($column,$data, $excelFileName);
?>
